package com.aishua.andpaydemo.fragment;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.aishua.andpaydemo.R;
import com.aishua.andpaydemo.adapter.CaifuAdapter;
import com.aishua.andpaydemo.adapter.ShopAdapter;
import com.aishua.andpaydemo.fragment.caifufragment.BaoxianFragment;
import com.aishua.andpaydemo.fragment.caifufragment.JiekuanFragment;
import com.aishua.andpaydemo.fragment.caifufragment.LicaiFragment;
import com.aishua.andpaydemo.fragment.shopmarketfagment.FujianShangjiaFragment;
import com.aishua.andpaydemo.fragment.shopmarketfagment.ShopCityFragment;
import com.aishua.andpaydemo.utils.TableLayoutChangeColorUtils;

import java.util.ArrayList;

/**
 * Created by aishua on 2018/5/15.
 */

public class ShopFragment extends BaseFragment {

    private TabLayout tab_shop;
    private ViewPager vp_shop_content;
    private ArrayList<BaseFragment> baseFragments;
    private ArrayList<String> list_title;
    private ImageView img_yanshen;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        View view = View.inflate(getContext(), R.layout.fragment_shop, null);
        initView(view);
        return view;
    }


    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void initView(View view) {

        tab_shop = view.findViewById(R.id.tab_shop);
        vp_shop_content = view.findViewById(R.id.vp_shop_content);
        img_yanshen = view.findViewById(R.id.img_yanshen);
        int clolrID = TableLayoutChangeColorUtils.getThemeColorId(getContext());
        tab_shop.setBackground(getContext().getDrawable(clolrID));
        img_yanshen.setBackground(getContext().getDrawable(clolrID));
        //将名称加载tab名字列表，正常情况下，我们应该在values/arrays.xml中进行定义然后调用
        list_title = new ArrayList<>();
        list_title.add("在线商城");
        list_title.add("附近商家");

        //设置TabLayout的模式
        tab_shop.setTabMode(TabLayout.MODE_FIXED);
        //为TabLayout添加tab名称
//        tab_caifu.addTab(tab_caifu.newTab().setText(list_title.get(0)));
//        tab_caifu.addTab(tab_caifu.newTab().setText(list_title.get(1)));
//        tab_caifu.addTab(tab_caifu.newTab().setText(list_title.get(2)));

        initFragment();
        vp_shop_content.setAdapter(new ShopAdapter(getChildFragmentManager(),baseFragments,list_title));

        tab_shop.setupWithViewPager(vp_shop_content);
    }
    private FujianShangjiaFragment licaiFragment;
    private ShopCityFragment shopCityFragment;
    public void initFragment() {

        baseFragments = new ArrayList<>();
        baseFragments.clear();

        shopCityFragment = new ShopCityFragment();
        licaiFragment  = new FujianShangjiaFragment();

        baseFragments.add(shopCityFragment);
        baseFragments.add(licaiFragment);
    }


}
